package world

import (
	"MetroBuilderGameJam/gameEngine/utils"
	"math/rand"
)

func NewPassengerFlowOrganizer() *CityCitizens {
	return &CityCitizens{}
}

type CityCitizens struct {
}

func (c *CityCitizens) AddPassenger(existsStations []*Station) *Passenger {
	station := c.randomStation(existsStations)
	p := NewRandomPassenger(c.availableShapes(existsStations))
	station.AddPassenger(p)
	return p
}

func (c *CityCitizens) randomStation(stations []*Station) *Station {
	r := rand.Intn(len(stations))
	return stations[r]
}

func (c *CityCitizens) availableShapes(stations []*Station) []StationType {
	availableShapes := make(map[StationType]struct{})
	for _, station := range stations {
		availableShapes[station.shape] = struct{}{}
	}
	return utils.MapKeys[StationType, struct{}](availableShapes)
}
